<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			this.checkSDKVersion()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			checkSDKVersion() {
				const SDKVersion = wx.getAppBaseInfo().SDKVersion 
				const minVersion = '2.24.0' // 要求的最低版本
				
				if (this.compareVersion(SDKVersion, minVersion) < 0) {
					uni.showModal({
						title: '版本提示',
						content: `朋知云学提醒你,当前微信版本过低,请升级到最新版本哦`,
						showCancel: false
					})
				}
			},
			
			compareVersion(v1, v2) {
				v1 = v1.split('.')
				v2 = v2.split('.')
				const len = Math.max(v1.length, v2.length)
				
				while (v1.length < len) v1.push('0')
				while (v2.length < len) v2.push('0')
				
				for (let i = 0; i < len; i++) {
					const num1 = parseInt(v1[i], 10)
					const num2 = parseInt(v2[i], 10)
					
					if (num1 > num2) return 1
					if (num1 < num2) return -1
				}
				return 0
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
